package com.arvin.controller;

import com.arvin.pojo.Log;
import com.arvin.pojo.PageBean;
import com.arvin.pojo.Result;
import com.arvin.service.LogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/log")
@Tag(name = "日志相关接口",description = "日志相关接口")
@Slf4j
public class LogController {

    @Autowired
    private LogService logService;

    /**
     * 日志分页
     * @param username
     * @param logType
     * @param logBeginTime
     * @param logEndTime
     * @param pageSize
     * @param page
     * @return
     */
    @Operation(summary = "日志分页",description = "日志分页")
    @GetMapping("/getLogInfo")
    public Result<PageBean> getLogInfo(String username, String logType,
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate logBeginTime,
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate logEndTime,
                                       Integer pageSize, Integer page){
        PageBean pageBean = logService.getLogInfo(username,logType,logBeginTime,logEndTime,page,pageSize);
        log.info("获取日志分页信息{}",pageBean);
        return Result.success(pageBean);
    }

    /**
     * 获取全部日志信息
     * @return
     */
    @Operation(summary = "获取全部日志信息",description = "获取全部日志信息")
    @GetMapping("/getAllLog")
    public Result<List<Log>> getAllLog(){
        List<Log> logList = logService.getAllLog();
        log.info("获取全部日志信息{}",logList);
        return Result.success(logList);
    }

    /**
     * 根据id删除日志
     * @param logIds
     * @return
     */
    @Operation(summary = "根据id删除日志",description = "根据id删除日志")
    @DeleteMapping("/deleteLogById/{logIds}")
    public Result deleteLogByIds(@PathVariable List<Integer> logIds){
        logService.deleteLogByIds(logIds);
        return Result.success();
    }
//    export function deleteLogByIds(logIds: number[]){
//        return request({
//                url: '/log/deleteLogById/' + logIds,
//                method: "delete"
//    })
//    }
}
